package com.softline.documentsmall.controller;


import com.softline.documentsmall.entity.EntryDetails;
import com.softline.documentsmall.ret.ReturnVO;
import com.softline.documentsmall.ret.ReturnVOUtils;
import com.softline.documentsmall.service.EntryDetailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author zhongweicheng
 * @date 2020/8/25 10:11
 */
@Api(value="条目记录主表相关接口",tags={"条目记录主表相关接口"})
@RestController
@RequestMapping("/detail")
@CrossOrigin(allowCredentials = "true",allowedHeaders = "*")
public class EntryDetailController {

    @Autowired
    EntryDetailService entryDetailService;


    @ApiOperation(value="按照条件获取条目记录", notes = "按照条件获取条目记录")
    @GetMapping(value = "/getEntryDetail")
    public ReturnVO getIssues(EntryDetails entryDetails){
        return entryDetailService.findByParams(entryDetails);
    }

    @ApiOperation(value="用户更新条目主记录", notes = "用户更新条目主记录,须传递id")
    @PostMapping(value = "/updateEntryDetail")
    public ReturnVO update(@RequestBody @Valid EntryDetails entryDetails){
        return entryDetailService.updateById(entryDetails);
    }

    @ApiOperation(value="新增条目主记录", notes = "新增条目主记录")
    @PostMapping(value = "/insertDetailSubmit")
    public ReturnVO insert(@RequestBody EntryDetails entryDetails){
        return entryDetailService.insertEntryDetails(entryDetails);
    }


    @ApiOperation(value="软删除条目主记录", notes = "软删除条目主记录")
    @PostMapping(value = "/softDeleteEntryDetail")
    public ReturnVO softDelete(Integer id){
        return entryDetailService.softDeleteById(id);
    }


    @ApiOperation(value="根据字典id语言类型标题获取条目记录", notes = "根据字典id语言类型标题获取条目记录")
    @GetMapping(value = "/getDetailByDictionaryIdLanguageTitle")
    public ReturnVO findByDictionaryIdLanguageTitle(Integer dictionaryId, String language, String title){
        return ReturnVOUtils.success(entryDetailService.findByDictionaryIdLanguageTitle(dictionaryId,language,title));
    }

    @ApiOperation(value="触发所有词条新增术语解读目录", notes = "触发所有词条新增术语解读目录")
    @PostMapping(value = "/insertBatch")
    public ReturnVO insertBatch(){
        entryDetailService.insertBatch();
        return ReturnVOUtils.success("术语解读目录新增成功");
    }

    @ApiOperation(value="按照条件获取条目记录", notes = "按照条件获取条目记录")
    @GetMapping(value = "/getMaxSort")
    public ReturnVO getMaxSort(@RequestParam(name = "dictionaryId")Integer dictionaryId,@RequestParam(name = "type")String  type){
        return ReturnVOUtils.success(entryDetailService.getMaxSort(dictionaryId,type));
    }


}
